
<?php 
?>

<script type="text/javascript">
function commentValidation(id)
{
	var comment = prompt("Zadej nový komentář","..."); 

	if (comment != "" && comment != null && comment.length < 251) {
		document.getElementById("se_new_comment" + id).value = comment;
		return true ;
	} else {
		return false ;
	}	  
}
</script>  

<form method="get" action="<?php echo JRoute::_('index.php?option=com_sevent'); ?>" id="adminForm">
	<?php 
	if ($this->userId != -1)
	{
		echo '<input type="submit" value="'.JText::_('COM_SEVENT_NEW_EVENT_BUTTON').'" class="button"/>';
	}
	else
	{
		echo '<p>'.JText::_('COM_SEVENT_LOGIN_WARNING_MESSAGE').'</p>';
  }
	?>	
	<hr/>
	<hr/>
	<fieldset>
	<input type="hidden" name="option" value="com_sevent" />
	<input type="hidden" name="task" value="newEvent" />
	<input type="hidden" name="view" value="events" />
	<?php echo JHTML::_( 'form.token' );  ?> 
	</fieldset>
</form> 

<?php 
	$display_date = date("Y-m-d H:i:s"); //MySQL date format
	$display_date = date('Y-m-d H:i:s', strtotime($display_date . ' - 1 hour'));

	$index = 0;
	
	
	foreach ($this->events as $event)
	{	
		
		if($index % 2 == 0)
		{
			$sec_id = 'sevent-l';
		}
		else 
		{
			$sec_id = 'sevent-r';
		}
		
		$index ++;
			
		if($event->date_time >= $display_date)
		{
			echo '<div id="sevent" class="'.$sec_id.'">';
		}
		else
		{
			echo '<div id="sevent-old" class="'.$sec_id.'">';
		}
		
		if($event->user_id != -1)
		{
			$user = JFactory::getUser($event->user_id);
			$username=$user->get('username');
		}
		else 
		{
			$username = 'Host';
		}
		
		echo '<b>'.JText::_('COM_SEVENT_EVENT_KIND_LABEL').' </b>' .$this->event_types[$event->event_type - 1] .'&nbsp &nbsp &nbsp';
		
		echo '<b>'.JText::_('COM_SEVENT_EVENT_DATE_LABEL').' </b>' .substr_replace($event->date_time ,"",-3) .'  <br/>';
		
		echo '<b>'.JText::_('COM_SEVENT_EVENT_CHALLENGER_LABEL').' </b>' .$username .'<br/>';
		
		echo '<b>'.JText::_('COM_SEVENT_EVENT_COMMENT_OF_CHALLENGER_LABEL').'  </b>' .$event->comment .'<br/>';
		
		echo '<b>'.JText::_('COM_SEVENT_EVENT_PARTICIPATION_CONFIRMED_BY_LABEL').' </b>';
		
		$model = $this->getModel('Events') ;
		$participants = $model->getParticipants($event->id);
		
		foreach ($participants as $key => $participant)
		{
			if($key != 0)
			{
				echo ', ';
			}
			$user = JFactory::getUser($participant);
			echo $user->get('username');

		}

		if($event->date_time >= $display_date)
		{
			if ($this->userId != -1)
			{
				echo '<form method="get" action="index.php" id="adminForm">';
				echo '<fieldset>';
				echo '<input style="float:left;" type="submit" value="'.JText::_('COM_SEVENT_EVENT_CONFIRM_BUTTON').'" class="inputbox"/>';
				echo '<input type="hidden" name="option" value="com_sevent" />';
				echo '<input type="hidden" name="task" value="newParticipant" />';
				echo '<input type="hidden" name="view" value="events" />';
				echo '<input type="hidden" name="event_id" value="'.$event->id.'" />';
				echo JHTML::_( 'form.token' );
				echo '</fieldset>';
				echo '</form> ';
			}
			
			if($model->isTheUserAutor($event->id, $this->userId))
			{
				echo '<form method="post" action="index.php" id="adminForm" onsubmit="return commentValidation('.$event->id.')">';
				echo '<fieldset>';
				echo '<input style="float:left;" type="submit" value="'.JText::_('COM_SEVENT_EVENT_CHANGE_COMMENT_BUTTON').'" class="inputbox"/>';
				echo '<input type="hidden" name="option" value="com_sevent" />';
				echo '<input type="hidden" name="task" value="changeComment" />';
				echo '<input type="hidden" name="view" value="events" />';
				echo '<input type="hidden" name="event_id" value="'.$event->id.'" />';
				echo '<input type="hidden" id="se_new_comment'.$event->id.'" name="se_new_comment" />';
				echo JHTML::_( 'form.token' );
				echo '</fieldset>';
				echo '</form> ';			
			}
		}
	
		echo '</div>';
	}
	
	echo '<div class="pagination">';
	echo $this->pagination->getPagesLinks();
	echo '</div>';
?>

